#include "global.h"
#include "cvt.h"


int main()
{
	int numbound;
	Polygon bound;
	std::vector<Point> v_p;
	std::cin>>numbound;
	for (int i = 0; i < numbound; ++i)
	{
		Point p;
		std::cin>>p;
		bound.push_back(p);
	}
	
	int numseeds;
	std::cin>>numseeds;
	for (int i = 0; i < numseeds; ++i)
	{
		Point p;
		std::cin>>p;
		v_p.push_back(p);
	}
        

	
	std::cout<<v_p.size()<<std::endl;
	
	DOUBLE threshold = 1e-7;
	for (int j = 0; ; ++j)
	{
		CVT obj(bound,v_p);
		vector <Point> v_p_old (v_p);

		v_p.clear(); 
		for (unsigned i = 0; i < obj.size(); ++i)
		{
			Polygon face;
			Point cen;
			obj.convert_face_region(i, face);
			centroid(face, cen);

			v_p.push_back(cen);
		}
		

                DOUBLE e = energy_function(v_p, v_p_old);
                std::cerr<<"Energy     : "<<j<<' '<< e <<std::endl;		
                if (e < threshold) break;
	}
    	

	return 0;
}
